import Search from 'models/search';

import moment from 'moment';

export default class MerchantStatSearch extends Search {
  branchStatus = '';
  partnerStatus = '';
  startTime = null;
  endTime = null;

  propertyList = ['branchStatus','partnerStatus','startTime','endTime'];

  constructor(){
    super();
    this.setOldData();
  }
  
  checkValid(){
    let startTime = this.startTime;
    let endTime = this.endTime;
    if (startTime !== null || endTime !== null) {
      if (startTime === null) {
        return 'startTime';
      }
      if (endTime === null) {
        return 'endTime';
      }
    }

    return '';
  }

  getObject(){
    let postData = {};
    let fields = ['branchStatus','partnerStatus'];
    this.setPostData(postData, fields);
    
    let startTime = this.startTime;
    if (startTime !== null) {
      postData.branchPartnerStartCreateTime = moment(startTime).format('YYYY-MM-DD');
    }

    let endTime = this.endTime;
    if (endTime !== null) {
      postData.branchPartnerEndCreateTime = moment(endTime).format('YYYY-MM-DD');
    }
    return postData;
  }
}